package 剑指Offer.Offer06;

import java.util.ArrayList;

/**
 * @Author cheng.song
 * @create 2021/11/9 13:59
 */
public class 从尾到头打印链表 {
    public static void main(String[] args) {
        ListNode head = new ListNode(1);
        head.next=new ListNode(3);
        head.next.next=new ListNode(2);
        reversePrint(head);
    }

    public static  int[] reversePrint(ListNode head) {
        int size = 0;
        ListNode current = head;
        while (current!=null){
            current=current.next;
            size++;
        }
        int[] n= new int[size];
        current = head;
        while (current!=null){
            n[--size] =current.val;
            current=current.next;
        }
        return n;
    }
}
class ListNode {
    int val;
    ListNode next;
    ListNode(int x) { val = x; }
}